﻿package gui.hug;

class LinkButton extends Button {
    public var fontSize : UInt; // Font Size
    public var textFormat : UInt; // Text Format
    public var w : Float; // Width  (used for multiline LinkButton, in other case should be equal to zero)
    public var h : Float; // Height (used for multiline LinkButton, in other case should be equal to zero)
    
    public function new(label : String, x : Float, y : Float, font_size : UInt = 11, width : Float = 0, height : Float = 0)
    {
		textFormat = 0;
		fontSize = font_size;
		w = width;
		h = height;
		super(label, x, y, Button.LINK_BUTTON);
		//updateButton();
    }

    public function getFontSize() : UInt
    {
      return fontSize;
    }
    
    public function setFontSize(val : UInt)
    {
      fontSize = val;
      updateButton();
    }

    public function getBold() : Bool
    {
      return 0 != (textFormat & Utils.TXT_BOLD);
    }
    
    public function setBold(val : Bool)
    {
      if (val) 
        textFormat |= Utils.TXT_BOLD;
      else
        textFormat &= ~Utils.TXT_BOLD;
      
      updateButton();
    }
    
    public function getCentered() : Bool
    {
      return 0 != (textFormat & Utils.TXT_CENTER);
    }
    
    public function setCentered(val : Bool)
    {
      if (val) 
        textFormat |= Utils.TXT_CENTER;
      else
        textFormat &= ~Utils.TXT_CENTER;
      
      updateButton();
    }
    
    public function getMaxWidth() : Float
    {
      return w;
    }
    
    public function setMaxWidth(val : Float)
    {
      w = val;
      updateButton();
    }
    
    public function getIntVal() : Int // Used in Pagination, for example
    {
			if (label == "«") return 1;
			if (label == "»") return -1;
			return Std.parseInt(label);
    }
    
    public override function updateButton() {
      upState   = new LinkButtonDS(bt, 0, label, fontSize, textFormat, w, h);
      overState = new LinkButtonDS(bt, 1, label, fontSize, textFormat, w, h);
      downState = hitTestState = overState;
    }
}
